package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/7 14:49
 */
public class M0103 {

    // https://leetcode-cn.com/problems/string-to-url-lcci/
    public static String replaceSpaces(String S, int length) {
        char[] str = S.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            if(str[i] == ' ') {
                sb.append("%20");
            }else {
                sb.append(str[i]);
            }
        }
        return sb.toString();
    }

    public static String compareM(String S, int length) {
        return S.substring(0, length).replaceAll(" ", "%20");
    }


    // for test
    public static void main(String[] args) {

    }

}
